//app.js
var request = require("/utils/request.js");
App({
  onLaunch: function (options) {
    console.log(options)
    var leadUserId;
    if (options.query.leadUserId){
      leadUserId = options.query.leadUserId;
    }
    var that = this;

  },

  // 查看是否授权
  getSetting: function (that) {
    var app = this;

    wx.getSetting({
      success: function (res) {
        console.log(res)
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称
          wx.getUserInfo({
            success: function (res) {
              console.log(res.userInfo)
              app.globalData.userInfo = res.userInfo
              that.setData({
                access: "",
                userInfo: res.userInfo
              })
            }
          })

        } else {
          that.setData({
            access: 1
          })
          return
        }
      }
    })

  },
  bindUser:function(options){
    var that = this;
    // 登录
    var sessionId = wx.getStorageSync('sessionId');
    if (sessionId){
      if (options.userId) {
        request.request(that.globalData.bindLeadUser, { leadUserId: options.userId }, function (res) {
          console.log(res)
        })
      }
    }else{
      wx.login({
        success: res => {
          // return
          request.request(that.globalData.login, { code: res.code }, function (res) {
            console.log(res)
            if (res.code == 0) {
              wx.setStorageSync("sessionId", res.sessionId);
              wx.setStorageSync("openId", res.openId);
              if (options.userId) {
                request.request(that.globalData.bindLeadUser, { leadUserId: options.userId }, function (res) {
                  console.log(res)
                })
              }
            }
          })
        }
      })
    }
  },


  globalData: {
    userInfo: null,
    mobile:"",
    login: "/app/weixin/miniProgramLogin",//登录
    miniLogin: "/app/weixin/miniLogin",//登录2
    indexPic: "/app/common/indexPic",//首页banner图
    classifyList: "/app/common/classifyList",//分类列表图
    getOrderList: "/app/order/getOrderList",//订单列表
    getOrderDetail: "/app/order/getOrderDetail",//订单详情
    getScheduleList: "/app/order/getScheduleList",//进度列表
    getUserInfo: "/app/user/getUserInfo",//获取用户信息
    updateUserInfo: "/app/user/updateUserInfo", //修改用户信息
    bindMobile: "/app/user/bindMobile", //绑定手机号
    brandList: "/app/common/brandList",//获取品牌列表
    getStoreList: "/app/store/getStoreList", //获取门店列表
    seekFile: "/app/common/seekFile",//查看、下载附件
    getClassifyPage: "/app/common/getClassifyPage",//首页产品分类表
    getProdeuctList: "/app/store/getProdeuctList",//获取门店产品列表
    getStoreDetail: "/app/store/getStoreDetail",//获取商家详情
    getStoreCaseDetail: "/app/store/getStoreCaseDetail",//获取商家案例详情
    getProductDetail: "/app/store/getProductDetail",//获取产品详情
    getSnList: "/app/store/getSnList",//app/store/getSnList
    getPicDetail: "/app/common/getPicDetail",//获取图文详情
    getCityList: "/app/common/getCityList", //获取城市列表
    getScheduleTime: "/app/order/getScheduleTime",//获取时间排期表
    addOrder: "/app/order/addOrder",//下单
    payForOrder: "/app/order/payForOrder",//订单支付
    changeOrderNum: "/app/order/changeOrderNum",//修改订单数量
    getScheduleList: "/app/order/getScheduleList", //获取进度列表
    setSchedule: "/app/order/setSchedule",//预约拍摄时间
    getReasonList: "/app/common/getReasonList",//获取原因列表
    updateOrder: "/app/order/updateOrder", //订单取消、退款
    commentOrder: "/app/order/commentOrder",//评价订单
    proBindMobile: "/app/user/proBindMobile",//小程序绑定手机号
    getSelectedOrderTime: "/app/order/getSelectedOrderTime",//获取订单时间
    getSysParam: "/app/common/getSysParam",//获取系统参数
    getUserInfo: "/app/user/getUserInfo", //获取用户信息
    encodeQrcodeImg: "/app/user/encodeQrcodeImg", //生成二维码图片返回
    getScheduleDetail: "/app/order/getScheduleDetail",//获取进度详情
    addAdvice: "/app/order/addAdvice",//投诉建议
    getAccesstoken: "/app/common/getAccesstoken",//获取accesstoken
    bindLeadUser: "/app/user/bindLeadUser",//绑定上级用户
    getWXQARCode: "/app/common/getWXQARCode",//小程序二维码
  }
})